//
// Copyright (c) 2024 BPer
//
#ifndef __BPerAudioEncoderrHandle__
#define __BPerAudioEncoderrHandle__
#include <bperutil/sys/BPerThread2.h>
#include <bperutil/buffer/BPerAudioEncoderBuffer.h>
#include <bperutil/buffer/BPerAudioPlayBuffer.h>
#include <bperencoder/BPerAudioEncoder.h>
#include <vector>


using namespace std;
class BPerAudioEncoderHandle:public BPerThread,public BPerEncoderCallback
{
public:
	BPerAudioEncoderHandle(BPerAudioInfo *pcontext);
	~BPerAudioEncoderHandle(void);

private:
	int32_t m_isInit;

public:
	void init();
	void stop();
	void setInAudioBuffer(BPerAudioBuffer *pbuf);
	void setOutAudioBuffer(BPerAudioEncoderBuffer *pbuf);

	void onVideoData(BPerFrame* pframe);
	void onAudioData(BPerFrame* pframe);
	int32_t m_isStart;
	int32_t m_uid;



protected:
	void run();
	void stopLoop();
	void startLoop();

void saveFile(char *fileName, uint8_t *pBuffer, long BufferLen);

private:

	BPerAudioEncoder *m_enc;
	int32_t m_isConvert;
	BPerAudioBuffer *m_in_audioBuffer;
	BPerAudioEncoderBuffer *m_out_audioBuffer;
	BPerAudioInfo *m_context;
	void Encoder(int32_t isIframe,uint8_t*src,int32_t  p_buflen,uint8_t *dest,int32_t *p_destLen);

};
#endif
